<template>
	<div class="grayBg">
		<div class="">
			<div class="compareBox">
				<div class="content">
					<div class="contentBox">
						<div class="items">
							<div class="item thead">
								<div class="th">年份</div>
								<div class="th">公告来源</div>
								<div class="th">职位名称</div>
								<div class="th">职位代码</div>
								<div class="th">招考人数</div>
								<div class="th">职位性质</div>
								<div class="th">地区</div>
								<div class="th">所属系统</div>
								<div class="th">部门名称</div>
								<div class="th">部门代码</div>
								<div class="th">用人处（科）室</div>
								<div class="th">招考对象</div>
								<div class="th">学历</div>
								<div class="th">专业</div>
								<div class="th">工作经历</div>
								<div class="th">政治面貌</div>
								<div class="th">岗位最低服务年限</div>
								<div class="th">其他信息</div>
							</div>
							<div class="overBox">
								<div class="flexBox">
									<div class="item tbody" v-for="(item,index) in favList" :key="index">
										<div class="td" @click="showToast('default' ,item.zwinfo.year)">{{ item.zwinfo.year ? item.zwinfo.year : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.ggxx)">{{ item.zwinfo.ggxx ? item.zwinfo.ggxx : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.zwmc)">{{ item.zwinfo.zwmc ? item.zwinfo.zwmc : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.zwdm)">{{ item.zwinfo.zwdm ? item.zwinfo.zwdm : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.zkrs)">{{ item.zwinfo.zkrs ? item.zwinfo.zkrs : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.zwxz)">{{ item.zwinfo.zwxz ? item.zwinfo.zwxz : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.city)">{{ item.zwinfo.city ? item.zwinfo.city : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.xt)">{{ item.zwinfo.xt ? item.zwinfo.xt : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.bmmc)">{{ item.zwinfo.bmmc ? item.zwinfo.bmmc : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.bmdm)">{{ item.zwinfo.bmdm ? item.zwinfo.bmdm : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.yrcs)">{{ item.zwinfo.yrcs ? item.zwinfo.yrcs : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.zkdx)">{{ item.zwinfo.zkdx ? item.zwinfo.zkdx : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.xl)">{{ item.zwinfo.xl ? item.zwinfo.xl : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.zy)">{{ item.zwinfo.zy ? item.zwinfo.zy : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.gzjl)">{{ item.zwinfo.gzjl ? item.zwinfo.gzjl : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.zzmm)">{{ item.zwinfo.zzmm ? item.zwinfo.zzmm : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.fwnx)">{{ item.zwinfo.fwnx ? item.zwinfo.fwnx : '无' }}</div>
										<div class="td" @click="showToast('default' ,item.zwinfo.bz)">{{ item.zwinfo.bz ? item.zwinfo.bz : '无' }}</div>
									</div>
								</div>
							</div>
						</div>
						
					</div>
				</div>
			</div>
			
			
		</div>

		<div class="loadBox" v-if="loading">
			<u-loading-icon size="36" mode="circle" :vertical="true" color="red" text="加载中..." textSize="20"></u-loading-icon>
		</div>
		<!-- <share></share> -->
		<u-toast ref="uToast"></u-toast>
	</div>
</template>

<script>
	import {
		mapActions
	} from 'vuex';
	const db = wx.cloud.database()
	import share from '../../common/share/index.vue';
	export default {
		data() {
			return {
				searchInfo:"",
				showLogin: false,
				klcode:"",
				loading: true,
				status:"loadmore",
				loadEnd: true,
				page: 0,
				list:[],
				cityList:["哈尔滨","齐齐哈尔","牡丹江","佳木斯","大庆","鹤岗","伊春","鸡西","七台河","双鸭山","绥化","黑河","大兴安岭"],
				selectCity:"选择地区",
				showCity: false,
				sortList:['默认排序','招录人数优先'],
				selectSort:"默认排序",
				showSort: false,
				searchVal:"",
				clickSearch:false,
				favList:[],
				favIdList:[],
				openid:""
			};
		},
		onShareAppMessage(options) {
			let shareObj = {
			    title: "黑龙江省考-职位匹配",
			    path: '/pages/sk-tools/zwpp/index?name=' + this.name,
			    imageUrl: ''   
			};
			return shareObj
		},
		onShareTimeline(res) {
			let that = this;
			return {
				title: '黑龙江省考-职位匹配',
				query: "name=" + that.name
			};
		},
		onShow() {},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onPageScroll(e) {
			let that = this;
			that.scrollTop = e.scrollTop;
		},
		onLoad(options) {
			
		},
		computed: {
			searchtimes() {
				return this.$store.getters.searchtimes ? this.$store.getters.searchtimes : '';
			},
			userphone() {
				return this.$store.getters.userphone ? this.$store.getters.userphone : '';
			}
		},
		mounted() {
			if (this.searchtimes > 0) {
				this.searchNum = this.searchtimes
			}
		},
		watch: {
			
		},
		created() {
			let that = this;
			that.getopenid()
		},
		methods: {
			...mapActions(['LogSetSearchtimes','LogSetPhone']),
			getopenid(){
				let that = this
				wx.cloud.callFunction({
					name: 'getopenid',
					data: {},
					complete: res => {
						that.openid =res.result.openid
						that.getAllFav()
					}
				})
			},
			checkKlm(){
				let that = this
				wx.cloud.callFunction({
					name: 'get_klm',
					data: {},
					complete: res => {
						if(res.result.klm == that.klcode){
							that.sk_bl_hasLogin = true
							that.showLogin = false
							wx.setStorageSync('sk_bl_hasLogin', true);
						}else{
							uni.showToast({
								icon: "error",
								title: '口令码不正确'
							});
							that.showLogin = true
						}
					}
				})
			},
			showDetail(info){
				uni.navigateTo({
					url: '../zwxq/index?colname=' + info.colname + '&id=' + info.zwid
				})
			},
			changeCity(e){
				this.selectCity = e.value[0]
				this.showCity = false
				this.page = 0
				this.list = []
				this.loading = true
				this.loadEnd = false
				this.status = 'loadmore'
				this.searchByBmmc()
				
			},
			changeSort(e){
				this.selectSort = e.value[0]
				this.showSort = false
				this.page = 0
				this.list = []
				this.loading = true
				this.loadEnd = false
				this.status = 'loadmore'
				this.searchByBmmc()
			},
			searchFuc(){
				let that = this
				if(!that.searchVal){
					that.clickSearch = false
				}else{
					that.clickSearch = true
				}
				that.page = 0
				that.list = []
				that.loading = true
				that.loadEnd = false
				that.status = 'loadmore'
				
				that.searchByBmmc()
			},
			searchByBmmc(){
				let that = this
				wx.cloud.callFunction({
					name: 'search_bmmc',
					data: {
						colname: that.searchInfo.colname,
						keyword: that.searchVal,
						selectSort:that.selectSort,
						city:that.selectCity,
						limit:20,
						page: that.page
					},
					complete: res => {
						if(res.result.length > 0){
							that.list = that.list.concat(res.result)
						}else{
							that.loadEnd = true
							that.status = 'nomore'
						}
						that.loading = false
					}
				})
			},
			changePath(path){
				uni.navigateTo({
					url: path
				})
			},
			addFav(info){
				let that = this
				if(that.favIdList.length >= 10){
					uni.showToast({
						title:"最多收藏10个！",
						icon:"error"
					})
					return
				}
				db.collection('1_hljsk_fav').add({
					data:{
						colname:that.searchInfo.colname,
						zwid:info._id,
						zwinfo:info,
						time: new Date()
					},
					success: res=>{
						that.favIdList.push(info._id)
					}
				})
			},
			getAllFav(){
				let that = this
				db.collection('1_hljsk_fav').where({
					_openid: that.openid
				}).get({
					success:res =>{
						that.favList = res.data
						let lists = that.favList.map(item => item.zwid)
						that.favIdList = lists
						that.loading  = false
					}
				})
			},
			removeFav(id){
				let that = this
				db.collection('1_hljsk_fav').where({
					_openid: that.openid,
					zwid:id
				}).remove({
					success:res =>{
						that.getAllFav()
					}
				})
			},
			showToast(type, info) {
				this.$refs.uToast.show({
					type: type,
					icon: false,
					title: '失败主题',
					message: info,
					duration: 1000
				})
			},
		},
		components: {share}
	};
</script>

<style lang="scss">
	@import url(./index.css);
</style>
